/*
 * @FileDescription:
 * @Author: 茆生涛
 * @Date: 2021-07-20 14:32:48
 * @LastEditors: 茆生涛
 * @LastEditTime: 2021-07-26 13:30:19
 */
import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import Login from '@/pages/login/login.vue'
import Md5 from '@/utils/md5'

Vue.use(Router)
const routesArr = [
  {
    path: '/',
    name: 'HelloWorld',
    component: HelloWorld
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  }
]

const router = new Router({
  routes: routesArr
})

router.beforeEach((to, from, next) => {
  const user = JSON.parse(localStorage.getItem('randomMenuUser'))
  if (user && user.name === 'ml' && user.password === Md5('123456', 'm', true)) {
    next()
  } else {
    if (to.name === 'Login') {
      next()
    } else {
      next({ name: 'Login' })
    }
  }
})

export default router
